package com.etc.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.etc.pojo.JSPUserInfo;
import com.etc.service.IJSPUserService;

@Controller
public class JSPController {

    
    @Autowired
    IJSPUserService service;
    
    @RequestMapping("JSP/login.action")
    public String login(JSPUserInfo ui, Model mod, HttpSession session) {
        
        JSPUserInfo user = service.findByUname(ui.getUsername());
        
        if (user == null) {
            mod.addAttribute("msg", "puser is not exsit");
            return "JSP/Index";
        } else if (!user.getPassword().equals(ui.getPassword())) {
            mod.addAttribute("msg", "password is not dui");
            return "JSP/Index";
        } 
        
        session.setAttribute("user", user);
        return "JSP/Frame";
    }
    
}
